const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
//const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const devMode = process.env.NODE_ENV !== 'production';

module.exports = {
    entry: {
        main: path.join(__dirname, "../src/index.js"),
        common: ['react', 'react-dom']
    },
    output: {
        publicPath: devMode ? '/' : '/boiler/',
        path: path.join(__dirname, "../build"),
        filename: "[name].js",

    },
    resolve: {
        extensions: ['.js', '.jsx', 'json', '.css'],
    },
    performance: {
        hints: false
    },
    module: {
        rules: [
            {
                test: /\.(js|jsx)?$/,
                loader: ['babel-loader']
            }, {
                test: /\.(scss|sass)$/,
                use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader', 'sass-loader']
            }, {
                test: /\.less$/,
                use: ['style-loader', 'css-loader', {
                    loader: 'less-loader',
                    options: {
                        lessOptions: {
                            // modifyVars: darkTheme,
                            javascriptEnabled: true
                        }
                    }
                }]
            }, {
                test: /\.css$/,
                use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader']
            }, {
                test: /\.html$/,
                use: [{ loader: 'html-loader', options: { minimize: true } }]
            }, {
                test: /\.(ico)$/,
                use: "raw-loader",
            }, {
                test: /\.(eot|ttf|woff|woff2)/,
                loader: 'file-loader?name=fonts/[name].[ext]'
            }, {
                test: /\.(svg|png|jpg|jpeg|gif|pdf)$/,
                loader: "file-loader?name=images/[name].[ext]"
            }, {
                test: /\.json$/,
                loader: 'json-loader'
            }]
    },
    plugins: [
        new HtmlWebpackPlugin({
            filename: "index.html",
            template: path.join(__dirname, "../public/index.html"),
            favicon: "public/favicon.ico",
        }),
        new MiniCssExtractPlugin({
            filename: devMode ? '[name].css' : '[name].[hash].css',
            chunkFilename: devMode ? '[name].css' : '[name].[hash].css',
        }),
        new ProgressBarPlugin()
    ]
}